const ErrorCode = {
  ERROR_CODE_SYSTEM_ERROR: {code: 'NEXHOME_0001', desc: '未知系统错误'},
  ERROR_CODE_PARAMS_ERROR: {code: 'NEXHOME_0002', desc: '参数校验错误'},
  ERROR_CODE_USER_NOT_FOUND: {code: 'NEXHOME_1001', desc: '用户不存在'},
  ERROR_CODE_NO_PERMISSION: {code: 'NEXHOME_1002', desc: '用户没有权限访问接口'},
  ERROR_UPLOAD_FAIL: {code: 'NEXHOME_1003', desc: '上传失败'},
  ERROR_CREATE_FAIL: {code: 'NEXHOME_1004', desc: '对象已存在，创建失败'},
}
module.exports.ErrorCode = ErrorCode;

module.exports.createSuccessResponse = function (result) {
  return {
    code: '0000', ret: 0, desc: 'success', result,
  };
};
module.exports.createSuccessListResponse = function (data, page) {
  return {
    code: '0000',
    ret: 0,
    desc: 'success',
    result: {
      data,
      page: page || {
        size: data.length, pageNumber: 0, totalPages: 1, totalElements: data.length,
      },
    },
  };
};

module.exports.createErrorResponse = function (errorCode) {
  return {
    code: errorCode ? errorCode.code : ErrorCode.ERROR_CODE_SYSTEM_ERROR.code,
    ret: -1,
    desc: errorCode ? errorCode.desc : ErrorCode.ERROR_CODE_SYSTEM_ERROR.desc,
  };
};
